<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            电梯名称：<input type="text" name="elevatorName"/>
                        </li>
                        <li>
                            困人类型：
                            <select name="tiringType">
                                <option value="">所有类型</option>
                                <option value="0">人工上报</option>
                                <option value="1">非平层停靠困人</option>
                                <option value="2">不开门困人</option>
                            </select>
                        </li>
                        <li>
                            上报时间：<input type="text" name="reportTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:elevatorTiring:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:elevatorTiring:remove')}]];
    var tiringState = [[${@dict.getType('business_tiring_state')}]];
    var tiringCause = [[${@dict.getType('business_tiring_cause')}]];
    var prefix = ctx + "business/elevatorTiring";

    $(function () {
        var options = {
            url: prefix + "/historyTiringInfoList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "电梯困人管理",
            sortName: "completeTime",
            sortOrder: "desc",
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'tiringId',
                    title: '困人ID',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'elevatorId',
                    title: '关联电梯ID',
                    visible: false
                },
                {
                    field: 'tiringCode',
                    title: '困人单号'
                },
                {
                    field: 'elevatorName',
                    title: '电梯名称',
                    formatter: function (value, row, index) {
                        return addClick(value, row);
                    }
                },
                {
                    field: 'tiringType',
                    title: '困人类型',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return "人工上报"
                        } else if (value == 1) {
                            return "非平层停靠困人"
                        } else if (value == 2) {
                            return "不开门困人"
                        }
                    }
                },
                {
                    field: 'reportTime',
                    title: '上报时间',
                    sortable: true
                },
                {
                    field: 'completeTime',
                    title: '完成时间',
                    sortable: true
                },
                {
                    field: 'tiringDuration',
                    title: '困人时长',
                    sortable: true
                },
                {
                    field: 'tiringState',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(tiringState, value);
                    }
                },
                {
                    field: 'tiringCause',
                    title: '原因',
                    formatter: function (value, row, index) {
                        let valueStr = value.split(",");
                        let str = "";
                        let val = "";
                        for (let i = 0; i < valueStr.length; i++) {
                            if (valueStr[i] == 115) {
                                val = "停电了";
                            } else if (valueStr[i] == 116) {
                                val = "电梯故障";
                            } else if (valueStr[i] == 117) {
                                val = "内有老人,小孩,孕妇";
                            } else if (valueStr[i] == 118) {
                                val = "内有危险用品";
                            } else if (valueStr[i] == 118) {
                                val = "搬货物使用不当";
                            } else if (valueStr[i] == 120) {
                                val = "其他";
                            }
                            if (i == valueStr.length - 1) {
                                str += val;
                            } else {
                                str += val + ",";
                            }
                        }
                        return $.table.tooltip(str);
                    }
                }]
        };
        $.table.init(options);
    });

    function addClick(value, row) {
        return '<a href="javascript:void(0)" onclick="enable(\'' + row.tiringId + '\')">' + value + '</a>'
    }

    function enable(tiringId) {
        createMenuItem(ctx + "business/elevatorTiring/historyTiringInfo/" + tiringId, "历史困人")
    }
</script>
</body>
</html>